﻿///***************************************************************
/// 시  스  템 : Updms.Com
/// 단위시스템 : COM
/// 계      층 : Presentation Layer
/// 프로그램명 : Com1015m
/// 파  일  명 : Com1015m.aspx.cs
/// 설      명 : 개인정보수정
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2008-08-06 송시명   최초 작성
///***************************************************************
using System;
using System.Data;
using System.Web.UI;

using SMFramework.Data;
using SMFramework.Utility;

using Base.AppFramework.Web.UI.CommandBar;
using Base.Dac;
using Updms.Com.Exe;


namespace Updms.Com
{
	public partial class Com1015m : Updms.Common.BaseClass.PageBase
	{
		#region 전역영역

		//프로그램상수
		public static readonly string PID = "Com1015m";
		public static readonly string gs_path_info = "/updms/Com/" + PID + ".aspx";

		Global global = new Global();
		CommCode.Com com = new CommCode.Com(LANG_SET);
		
		//검색
		protected string kw1 = "";	// 사용자아이디

		//메뉴 선택값
		protected string gs_sm = "";

		#endregion

		#region Page_Load, OnPageLoad

		protected void Page_Load(object sender, EventArgs e)
		{
			SetInit();
			if (!Page.IsPostBack)
			{
				// 최초 화면 로딩시 처리해야 할 부분
				OnPageLoad();
				SelectProcess();
			}
		}

		// OnPageLoad
		private void OnPageLoad()
		{
			SetLiterals(global.GetLabelInfoByPgmId(PID, LANG_SET));
			SetClientScript();
			SetStartPage();
			SetLanguageSet();
			SetSearchParameter();
		}

		#endregion

		#region InitializeComponent

		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
			this.PreRender += new System.EventHandler(this.Page_PreRender);
		}

		#endregion	
		
		#region SetClientScript

		private void SetClientScript()
		{
			ddl_start_page.Attributes.Add("onChange", "chkDisableOption(this)");
		}

		#endregion

		#region SetInit, SetSearchParameter, ShowKeywordLabel

		//초기값설정
		private void SetInit()
		{
			lbl_search_flag.Text = "INIT";

			gs_sm = (Request.QueryString["sm"] == null || Request.QueryString["sm"].Trim().Length != 7)
					? global.GetDirDepth(PID) : Request.QueryString["sm"].ToString();
		}

		//검색파라미터
		private void SetSearchParameter()
		{
			kw1 = USER_ID;
		}
		
		#endregion

		#region 마스터 Method (SetLanguageSet)

		//언어
		private void SetLanguageSet()
		{
			com.SetLanguageSet(rbl_language_set, LANG_SET);
		}

		#endregion

		#region 디테일 Method (SetStartPage)

		//시작페이지
		private void SetStartPage()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();
			Com1011m_NT _Com1011m_NT = new Com1011m_NT();

			lo_dp.AddProperty("ls_access_level", typeof(string), ACCESS_LEVEL);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

			lo_ds.Merge(_Com1011m_NT.GetStartPage(lo_dp));

			ddl_start_page.Items.Clear();
			ddl_start_page.DataSource = lo_ds;
			ddl_start_page.DataMember = "UPDMS_COM_PGM";
			ddl_start_page.DataTextField = "Text";
			ddl_start_page.DataValueField = "Value";
			ddl_start_page.DataBind();
		}

		#endregion

		#region CRUD (SelectProcess, InsertProcess, UpdateProcess, DeleteProcess, SearchProcess)

		//조회
		private void SelectProcess()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			lo_dp.AddProperty("ls_user_id", typeof(string), kw1);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

			using (Com1015m_NT _Com1015m_NT = new Com1015m_NT())
			{
				lo_ds.Merge(_Com1015m_NT.SelectByUserId(lo_dp));

				if (!DataSetUtil.CheckRowCount(lo_ds, "UPDMS_COM_USER_MGT"))
				{
					CallMsgBoxInAjax("MSG_ERR_111");	// 등록된 내용이 없습니다
				}
				else
				{
					lbl_user_id.Text = USER_ID;
					txt_nm.Text = DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_USER_MGT", "Nm");
					lbl_access_level.Text = ACCESS_LEVEL;
					lbl_user_div.Text = DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_USER_MGT", "User_Div_Nm");
					ddl_start_page.SelectedValue = DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_USER_MGT", "Start_Page");
					rbl_language_set.SelectedValue = DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_USER_MGT", "Language_Set");
					lbl_pw_update_dt.Text = "[" + DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_USER_MGT", "Post_Update_Day") + "] ";
					lbl_pw_update_dt.Text += DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_USER_MGT", "Pw_Update_Dt");
					txt_email.Text = DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_USER_MGT", "Email");
				}
			}
		}

		//수정
		private void UpdateProcess()
		{
			try
			{
				using (Com1015m_RT _Com1015m_RT = new Com1015m_RT())
				{
					int li_return = _Com1015m_RT.UpdateProcess(SetValue());
					string ls_msg_id = (li_return > 0) ? "MSG_INF_006" : "MSG_ERR_104";	//수정되었습니다:수정할 수 없습니다
					CallMsgBoxInAjax(ls_msg_id);

					SearchProcess();
				}
			}
			catch (Exception ex)
			{
				CallExceptionMsgBoxInAjax(ex);
			}
		}

		//검색
		private void SearchProcess()
		{
			lbl_search_flag.Text = "SEARCH";
			SetSearchParameter();
			SelectProcess();
		}

		#endregion

		#region SetValue

		//SetValue
		private DataPack SetValue()
		{
			DataPack lo_dp = new DataPack();

			lo_dp.AddProperty("User_Id",		typeof(string), USER_ID);
			lo_dp.AddProperty("Nm",				typeof(string), txt_nm.Text);
			lo_dp.AddProperty("Email",			typeof(string), txt_email.Text);
			lo_dp.AddProperty("Start_Page",		typeof(string), ddl_start_page.SelectedValue);
			lo_dp.AddProperty("Language_Set",	typeof(string), rbl_language_set.SelectedValue);
			lo_dp.AddProperty("Update_User",	typeof(string), USER_ID);
			lo_dp.AddProperty("Update_Dt",		typeof(string), "");
			
			return lo_dp;
		}


		#endregion

		#region Page_PreRender, ChangePageMode

		// Page_PreRender
		private void Page_PreRender(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				using (AccessCheck access = new AccessCheck())
				{
					//접근권한 체크
					if (!access.CheckPgmAccessGrant(PID, USER_ID, ACCESS_LOG_INFO))
					{
						Response.Redirect(URL_NO_AUTHORITY_REDIRECT_BASE);	//사용자의 권한은 요청하신 페이지를 볼 수 없습니다
					}
					bool lb_page_mode = access.CheckPgmUsingGrant(USER_DIV, PID);
					PagePreRender.SetVisibleCtrl(this, lb_page_mode, access.GetVisibleCtrl(PID));				
					
					//수정권한 없으면 비번수정 못한다
					ibtn_change_pw.Visible = lb_page_mode;
				}
			}
		}		

		#endregion

		#region 버튼이벤트

		//검색
		protected void ibtn_search_Click(object sender, EventArgs e)
		{
			SearchProcess();
		}

		//저장
		protected void ibtn_save_Click(object sender, EventArgs e)
		{
			//이전 세션값을 저장해둔다
			string currLangSet = Session["Lang_Set"].ToString();
			
			//세션값을 변경한다.
			Session["Lang_Set"] = rbl_language_set.SelectedValue;
			
			UpdateProcess();

			//언어가 변경된 경우 페이지 리로드 한다.
			if (currLangSet != rbl_language_set.SelectedValue)
			{
				Response.Redirect(Request.Url.ToString());
			}
		}		

		#endregion

	}
}
